﻿using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.AssetManage;
using LJX.SmartPark.Domain.SysTools;
using LJX.SmartPark.EntityFramework;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.AssetManage
{
    public class MonthStatisticsService:IMonthStatisticsService
    {
        private readonly IRepository<MonthStatistics> _MonthStatisticsService;
        private readonly StudentServerContext _context;
        public MonthStatisticsService(IRepository<MonthStatistics> MonthStatisticsService, StudentServerContext context)
        {
            _MonthStatisticsService = MonthStatisticsService;
            _context = context;
        }
        //总条数
        public int GetCount()
        {
            return _MonthStatisticsService.GetCount();
        }
        //多表联查分页查询
        public object GetMonthStatisticsData(SelectLogDatas select)
        {
            var MonthStatistics = _MonthStatisticsService.GetListQuery().ToList();
            var DeviceType = _context.DeviceType.ToList();
            var HouseData = _context.HouseData.ToList();
            var data = (from a in MonthStatistics
                        join b in DeviceType on a.Id equals b.Id
                        join c in HouseData on a.Id equals c.Id
                        select new
                        {
                            a.Id,
                            a.EquipmentNumber,
                            a.EquipmentName,
                            a.Month,
                            a.StartNum,
                            a.EndNum,
                            b.TypeName,
                            b.TypeCoding,
                            b.SuperClass,
                            c.HouseNum,
                            c.Floor,
                            c.Rooms
                        }).ToList();
            var totalCount = MonthStatistics.Count();

            data = data.Skip(((select.pageIndex - 1) * select.pageSize)).Take(select.pageSize).ToList();

            return new{ data, totalCount};

        }
        //页数条数model类
        public class SelectLogDatas
        {
            public int pageIndex { get; set; }
            public int pageSize { get; set; }
        }
    }
}
